package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * @ClassName CustomDialogDemo
 * @Description
 * @Author wangss
 * @date 2020.06.13 18:32
 * @Version 1.0
 */
public class CustomDialogDemo extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #fff2f2");

        Button button = new Button("弹框");

        AnchorPane.setTopAnchor(button, 20d);
        AnchorPane.setLeftAnchor(button, 20d);
        anchorPane.getChildren().addAll(button);
        Scene scene = new Scene(anchorPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(800d);
        primaryStage.setHeight(800d);
        primaryStage.setTitle("Dialog");
        primaryStage.setResizable(false);
        primaryStage.show();

        button.setOnAction(event -> {

            AnchorPane an = new AnchorPane();

            Scene sc = new Scene(an);
            Stage stage = new Stage();
            stage.setScene(sc);

            // 模态化窗口，注意这里，不能放到最后
            stage.initOwner(primaryStage);
            stage.initModality(Modality.WINDOW_MODAL);

            stage.initStyle(StageStyle.UTILITY);

            stage.setAlwaysOnTop(true);

            stage.setTitle("自定义弹框");
            stage.setWidth(300d);
            stage.setHeight(300d);
            stage.show();
        });
    }
}
